import { octpHttp } from "..";
import { Picture } from "../models/picture";

const url = (path: string) => `/picture/${path}`;
const request = octpHttp.request;

interface PictureUploadParams {
  file: File;
  type: "Avatar" | "Photo";
}

export const pictureUpload = (params: PictureUploadParams) => {
  const formData = new FormData();
  formData.append("file", params.file);
  formData.append("type", params.type);
  return request<Picture>({
    url: url("upload"),
    method: "post",
    headers: { "Content-Type": "multipart/form-data" },
    data: formData,
  });
};

export const getPictureById = (id: number) => {
  return request<Picture>({
    url: url("index"),
    method: "get",
    params: { id },
  });
};
